using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Woz
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
            this.SelectPenTool();

            // add our callbacks
            this.penCanvas1.StrokesSelected += new EventHandler(penCanvas1_StrokesSelected);
            this.penCanvas1.StrokesDeselected += new EventHandler(penCanvas1_StrokesDeselected);
            this.penCanvas1.StrokesCut += new EventHandler(penCanvas1_StrokesCut);
            this.penCanvas1.StrokesCopied += new EventHandler(penCanvas1_StrokesCopied);
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            this.SelectPointerTool();
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            this.SelectPenTool();

            /*System.Drawing.SolidBrush myBrush = new SolidBrush(Color.LightBlue);
            System.Drawing.Pen myPen = new Pen(Color.DarkBlue, 2.0f);

            System.Drawing.Graphics formGraphics;
            formGraphics = this.penCanvas1.CreateGraphics();
            System.Drawing.Rectangle r = new Rectangle(50, 50, 300, 300);
            formGraphics.DrawRectangle(myPen, r);
            formGraphics.FillRectangle(myBrush, r);
            myPen.Dispose();
            formGraphics.Dispose();*/   
        }

        private void SelectPointerTool()
        {
            // check the pointer button in the toolbar
            this.toolStripButton5.Checked = true;

            // uncheck the pen button
            this.toolStripButton6.Checked = false;

            // tell the canvas to switch modes
            this.penCanvas1.CurrentMode = WozControls.PenCanvas.PenCanvasMode.SelectEntities;     
        }

        private void SelectPenTool()
        {
            // check the pen button in the toolbar
            this.toolStripButton6.Checked = true; 

            // uncheck the pointer button
            this.toolStripButton5.Checked = false;

            // tell the canvas to switch modes
            this.penCanvas1.CurrentMode = WozControls.PenCanvas.PenCanvasMode.DrawStrokes;
        }

        void penCanvas1_StrokesSelected(object sender, EventArgs e)
        {
            // enable the relevant buttons
            this.toolStripButton1.Enabled = true;
            this.toolStripButton2.Enabled = true;
            //this.toolStripButton3.Enabled = true;
            this.toolStripButton4.Enabled = true;
            this.toolStripButton7.Enabled = true;

            this.cutToolStripMenuItem.Enabled = true;
            this.copyToolStripMenuItem.Enabled = true;
            //this.pasteToolStripMenuItem.Enabled = true;
            this.cloneToolStripMenuItem.Enabled = true;
            this.deleteToolStripMenuItem.Enabled = true;
        }

        void penCanvas1_StrokesDeselected(object sender, EventArgs e)
        {
            // disable the relevant buttons
            this.toolStripButton1.Enabled = false;
            this.toolStripButton2.Enabled = false;
            //this.toolStripButton3.Enabled = false;
            this.toolStripButton4.Enabled = false;
            this.toolStripButton7.Enabled = false;

            this.cutToolStripMenuItem.Enabled = false;
            this.copyToolStripMenuItem.Enabled = false;
            //this.pasteToolStripMenuItem.Enabled = false;
            this.cloneToolStripMenuItem.Enabled = false;
            this.deleteToolStripMenuItem.Enabled = false;
        }

        void penCanvas1_StrokesCut(object sender, EventArgs e)
        {
            // enable the paste buttons
            this.toolStripButton3.Enabled = true;
            this.pasteToolStripMenuItem.Enabled = true;
        }

        void penCanvas1_StrokesCopied(object sender, EventArgs e)
        {
            // enable the paste buttons
            this.toolStripButton3.Enabled = true;
            this.pasteToolStripMenuItem.Enabled = true;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            this.penCanvas1.CutSelectedStrokes();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            this.penCanvas1.CopySelectedStrokes();
        }
 
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            this.penCanvas1.PasteCopiedStrokes();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            this.penCanvas1.CloneSelectedStrokes();
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            this.penCanvas1.DeleteSelectedStrokes();
        }

        private void cutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.penCanvas1.CutSelectedStrokes();
        }

        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.penCanvas1.CopySelectedStrokes();
        }

        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.penCanvas1.PasteCopiedStrokes();
        }

        private void cloneToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.penCanvas1.CloneSelectedStrokes();
        }

        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.penCanvas1.DeleteSelectedStrokes();
        }        
    }
}